package com.ailink.concurrent.thread;

/**
 * Created by Administrator on 2018/9/26
 */
public class ThreadJoin implements Runnable {

//    private String name;
//
//    public ThreadJoin(String name) {
//        this.name = name;
//    }

    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + " " + i);
        }
    }

    public static void main(String[] args) {
        ThreadJoin threadJoin = new ThreadJoin();
        Thread thread1 = new Thread(threadJoin, "first");
        Thread thread2 = new Thread(threadJoin, "second");
        thread1.start();
        thread2.start();

//        try {
//            thread2.join();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println("main end");
    }
}
